package com.soft.javase.ch10.test.predicate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/7
 */
public class NameGender {
    public static void main(String[] args) {
        String[] array = { "张三,男", "李四,女", "王二麻子,女" };

        // 定义两个Predicate条件
        Predicate<String> isFemale = s -> s.split(",")[1].equals("女");
        Predicate<String> hasFourCharName = s -> s.split(",")[0].length() == 4;

        // 组合两个条件（AND关系）
        Predicate<String> combinedCondition = isFemale.and(hasFourCharName);

        // 使用Stream过滤并收集结果
        List<String> result = Arrays.stream(array)
                .filter(combinedCondition)
                .collect(Collectors.toList());

        // 或者使用ArrayList直接存储
        ArrayList<String> arrayListResult = new ArrayList<>(result);

        System.out.println(arrayListResult); // 输出: [王二麻子,女]
    }
}